Yes.
while
statement
Here is the while
statement, again:
while ( condition ) loop body // a statement or block statement statement after the loop
Here is how the while
statement works.
In the following, the word control means "the statement that is executing".
while
statement, the condition determines
if the loop body is to be executed.while
,
which again evaluates the condition. while
statement is finished, at least for now.Here is the while loop from the example program:
int count = 1; // start count out at one while ( count <= 3) // loop while count is <= 3 { System.out.println( "count is:" + count ); count = count + 1; // add one to count } System.out.println( "Done with the loop" ); // statement after the loop
This loop uses the variable count
.
It is started out at 1, then incremented each time the loop body
is executed until it reaches 4 and the condition is false.
Then the statement after the loop is executed.
The variable count
is used in three different activities.
It is initialized, tested, and changed.
Where in the program does each of these events take place?